package com.ncepu.clubmanagement.mapper;

import com.ncepu.clubmanagement.pojo.Club;
import com.ncepu.clubmanagement.pojo.ClubChangeableInfoWithManager;
import com.ncepu.clubmanagement.pojo.ClubModify;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClubInfoMapper {

    @Insert("insert into club_info(club_name, introduction, number, club_state, back_image, club_level, sch_id) values (#{clubName}, #{introduction}, " +
            "#{number}, #{clubState}, #{backImage}, #{clubLevel}, #{schId})")
    @Options(useGeneratedKeys = true, keyProperty = "clubId")
    public void addClubInfo(Club club);


    List<Club> getClubByClubName(String clubName);


    List<Club> getJoinedClubByClubNameAndPersonId(String clubName, Integer personId);

    List<Club> getManagedClubByClubNameAndPersonId(String clubName, Integer personId);

    @Insert("update club_info set number = number + 1 where club_id = #{clubId}")
    void addNumberByClubId(Integer clubId);

    @Select("SELECT ci.club_name, ci.introduction, ci.club_state, ci.back_image, ci.club_level, ci.number, cmr.person_id AS managerId " +
            "FROM club_info ci " +
            "LEFT JOIN club_management_relationship cmr ON ci.club_id = cmr.club_id " +
            "WHERE ci.club_id = #{clubId}")
    ClubChangeableInfoWithManager getClubChangeableInfoMapperByClubId(Integer clubId);

    @Update("update club_info set number = number - 1 where club_id = #{clubId}")
    void subNumberByClubId(Integer clubId);

    void updateClubInfo(ClubModify clubModify);

    @Select("select back_image from club_info where club_id = #{clubId}")
    String getClubBackImageByClubId(Integer clubId);

    @Update("update club_info set back_image = #{url} where club_id = #{clubId}")
    void updateClubBackImageByClubId(String url, Integer clubId);

    @Delete("delete from club_info where club_id = #{clubId}")
    void deleteClubInfoByClubId(Integer clubId);

    List<Integer> getManagedClubIdByClubNameAndPersonId(String clubName, Integer personId);
}
